$(function() {
	$('#submit_button').click(function(event){
		event.preventDefault();
		var url = 'http://ittalentsapi.bashibozuk.eu/users/register?X-GameID=103';
		var myData = {};
		myData.username = $('#username').val();
		myData.email = $('#email').val();
		myData.password = $('#password').val();
		myData.password_repeat = $('#repeat_password').val();
		myData.avatar = $('#avatar').val();
		$.ajax(url, {
			method: 'POST',
			data : myData,
			success: function(data) {
				console.log(data);
				if(data.errors) {
					$('.errors').html('');
					for(i in data.errors) {
						$('#errors_'+i).html(data.errors[i].join('<br>'));
					}
				}
				else {
					$('.errors').html('');
					$('#errors').html('You have successfully registered!');
				}
			}
		});		
	});
});